package com.eastfair.imaster.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.eastfair.auth.api.AuthServiceFeign;
import com.eastfair.auth.api.UserAccountServiceFeign;
import com.eastfair.auth.dto.OrganizationDTO;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.auth.entity.UserAccount;
import com.eastfair.auth.vo.UserAccountVo;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperCacheServiceImpl;
import com.eastfair.businpoint.BusinLoadUserRelevancePoint;
import com.eastfair.cache.exhibitor.ExhibitorCacheKeyBuilder;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.ExceptionCode;
import com.eastfair.core.model.CacheKeyBuilder;
import com.eastfair.core.snowflake.DefaultUidGenerator;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.imaster.dao.ExhibitorMapper;
import com.eastfair.imaster.dto.*;
import com.eastfair.imaster.entity.Company;
import com.eastfair.imaster.entity.Employee;
import com.eastfair.imaster.entity.Exhibitor;
import com.eastfair.imaster.mydao.MyExhibitorMapper;
import com.eastfair.imaster.service.CompanyService;
import com.eastfair.imaster.service.EmployeeService;
import com.eastfair.imaster.service.ExhibitorEmployeeService;
import com.eastfair.imaster.service.ExhibitorService;
import com.eastfair.imaster.vo.CompanyVo;
import com.eastfair.imaster.vo.EmployeeVo;
import com.eastfair.imaster.vo.ExhibitorEmployeeVo;
import com.eastfair.imaster.vo.ExhibitorVo;
import com.eastfair.log.point.PointUtil;
import com.eastfair.projectcore.api.ProjectCoreServiceFeign;
import com.eastfair.projectcore.entity.Area;
import com.eastfair.projectcore.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static com.eastfair.core.base.R.SUCCESS_CODE;

/**
 * <p>
 * 业务实现类
 * 展商
 * </p>
 *
 * @author ligang
 * @date 2021-09-07
 */
@Slf4j
@Service
@Transactional
@DS("#thread.tenant")
public class ExhibitorServiceImpl extends SuperCacheServiceImpl<ExhibitorMapper, Exhibitor> implements ExhibitorService {
    @Autowired
    private ProjectCoreServiceFeign projectCoreServiceFeign;

    @Autowired
    AuthServiceFeign authServiceFeign;
    @Autowired
    CompanyService companyService;
    @Autowired
    EmployeeService employeeService;
    @Autowired
    ExhibitorEmployeeService exhibitorEmployeeService;

    @Autowired
    ExhibitorService exhibitorService;

    @Autowired
    UserAccountServiceFeign userAccountServiceFeign;
    @Autowired
    private PointUtil pointUtil;

    @Autowired
    MyExhibitorMapper myExhibitorMapper;

    /**************sharding 分库分表操作 *****************/
    @Override
    public boolean updateByIdOfShard(Exhibitor entity) {
        UpdateWrapper<Exhibitor> updateWrapper = new UpdateWrapper<>();
        //可将指定字段更新为null
        updateWrapper.lambda().eq(Exhibitor::getProjectId, entity.getProjectId()).eq(Exhibitor::getId, entity.getId());
        entity.setProjectId(null);
        //删除缓存
        delCache(entity);
        return SqlHelper.retBool(this.getBaseMapper().update(entity, updateWrapper));
    }


    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<Exhibitor> modelList) {
        modelList.stream().forEach(s -> {
            s.setIsDeleted(BusinessConstant.YES);
        });
        // TODO: 2021/10/29 这里需要操作其他业务，如清空角色等
        return R.successDef();
    }


    @Override
    protected CacheKeyBuilder cacheKeyBuilder() {
        return new ExhibitorCacheKeyBuilder();
    }

    @Override
    protected R<Boolean> handlerSave(Exhibitor model) {
        //项目id
        model.setProjectId(ContextUtil.getProjectId());
        //雪花ID
        model.setId(DefaultUidGenerator.getUidOfProjectId(model.getProjectId()));
        return R.successDef();
    }

    @Override
    public R addCompanyOfExhibitor(ExhibitorDTO exhibitorDTO) {
        Exhibitor exhibitor = findCompany(exhibitorDTO.getCompanyId(), exhibitorDTO.getExhibitionId());
//        int i=1/0;
        if (exhibitor == null) {
            //新增
            exhibitor = new Exhibitor();
            exhibitor.setProjectId(ContextUtil.getProjectId());
            exhibitor.setExhibitionId(exhibitorDTO.getExhibitionId());
            exhibitor.setCompanyId(exhibitorDTO.getCompanyId());
            exhibitor.setExhibitionFloor(exhibitorDTO.getExhibitionFloor());
            exhibitor.setExhibitionBoothNumber(exhibitorDTO.getExhibitionBoothNumber());
            exhibitor.setExhibitionBoothPart(exhibitorDTO.getExhibitionBoothPart());
            exhibitor.setAttendTimes(exhibitorDTO.getAttendTimes());
            save(exhibitor);
            //组织角色：同步公司到展商
            CompanyVo companyVo = companyService.findById(exhibitorDTO.getCompanyId());
            if (companyVo != null) {
                OrganizationDTO organizationDTO = new OrganizationDTO();
                organizationDTO.setResourceId(exhibitorDTO.getCompanyId());
                organizationDTO.setName(companyVo.getName());
                organizationDTO.setTargetResourceId(exhibitorDTO.getExhibitionId());
                authServiceFeign.addCompanyOfExhibition(organizationDTO);
            }
        }

        return R.success(exhibitor);
    }

    @Override
    public R removeCompanyOfExhibitor(Long id) {
        Exhibitor exhibitor = getById(id);
        if (exhibitor == null) {
            //展商不存在
            return R.fail(ExceptionCode.EXHIBITOR_NULL);
        }
        exhibitor.setIsDeleted(BusinessConstant.DELETE_YES);
        updateById(exhibitor);
        //组织角色：同步公司到展商
        OrganizationDTO organizationDTO = new OrganizationDTO();
        organizationDTO.setResourceId(exhibitor.getCompanyId());
        organizationDTO.setTargetResourceId(exhibitor.getExhibitionId());
        authServiceFeign.removeCompanyOfExhibition(organizationDTO);
        return R.success();
    }

    @Override
    public Exhibitor findCompany(Long companyId, Long exhibitionId) {
        Exhibitor exhibitor = new Exhibitor();
        exhibitor.setCompanyId(companyId);
        exhibitor.setExhibitionId(exhibitionId);
        List<Exhibitor> exhibitorList = list(exhibitor, null);
        if (exhibitorList != null && !exhibitorList.isEmpty()) {
            return exhibitorList.get(0);
        }
        return null;
    }

    @Override
    public List<Exhibitor> list(Exhibitor exhibitor, List<Long> ids) {
        //查询
        QueryWrapper<Exhibitor> queryWrapper = new QueryWrapper<>();
        if (exhibitor != null) {
            if (exhibitor.getId() != null) {
                queryWrapper.lambda().eq(Exhibitor::getId, exhibitor.getId());
            }
            if (exhibitor.getExhibitionId() != null) {
                queryWrapper.lambda().eq(Exhibitor::getExhibitionId, exhibitor.getExhibitionId());
            }
            if (exhibitor.getCompanyId() != null) {
                queryWrapper.lambda().eq(Exhibitor::getCompanyId, exhibitor.getCompanyId());
            }
        }
        if (ContextUtil.getProjectId() != null) {
            queryWrapper.lambda().eq(Exhibitor::getProjectId, ContextUtil.getProjectId());
        }
        if (ids != null && !ids.isEmpty()) {
            queryWrapper.lambda().in(Exhibitor::getId, ids);
        }
        queryWrapper.lambda().eq(Exhibitor::getIsDeleted, BusinessConstant.DELETE_NO);
        return list(queryWrapper);
    }

    @Override
    public ExhibitorVo findCompanyOfAll(Long id) {
        Exhibitor exhibitor = getById(id);
        if (exhibitor == null) {
            return null;
        }
        ExhibitorVo exhibitorVo = new ExhibitorVo();
        BeanUtils.copyProperties(exhibitor, exhibitorVo);
        exhibitorVo.setId(exhibitor.getId());
        //查询展商员工信息
        List<ExhibitorEmployeeVo> exhibitorEmployeeVoList = exhibitorEmployeeService.queryUser(exhibitorVo.getId());
        exhibitorVo.setExhibitorEmployeeVoList(exhibitorEmployeeVoList);
        //加载公司信息
        CompanyVo companyVo = companyService.findById(exhibitor.getCompanyId());
        if (companyVo != null) {
            exhibitorVo.setCompanyVo(companyVo);
        }


        return exhibitorVo;
    }


    @Override
    public R<Page<ExhibitorVo>> queryPage(PageParams<ExhibitorDTO> params) {
        QueryWrapper<Exhibitor> queryWrapper = new QueryWrapper<>();
        ExhibitorDTO exhibitorDTO = params.getModel();
        queryWrapper.lambda().eq(Exhibitor::getIsDeleted, BusinessConstant.DELETE_NO);
        if (exhibitorDTO != null) {
            if (StringUtils.isNotBlank(exhibitorDTO.getExhibitionFloor())) {
                queryWrapper.lambda().like(Exhibitor::getExhibitionFloor, exhibitorDTO.getExhibitionFloor());
            }

            if (StringUtils.isNotBlank(exhibitorDTO.getExhibitionBoothNumber())) {
                queryWrapper.lambda().like(Exhibitor::getExhibitionBoothNumber, exhibitorDTO.getExhibitionBoothNumber());
            }

            if (StringUtils.isNotBlank(exhibitorDTO.getExhibitionBoothPart())) {
                queryWrapper.lambda().like(Exhibitor::getExhibitionBoothPart, exhibitorDTO.getExhibitionBoothPart());
            }
        }
        Page<Exhibitor> page = page(params.buildPage(), queryWrapper);
        Page<ExhibitorVo> voPage = ConvertUtil.convertPage(page, ExhibitorVo.class);
        List<ExhibitorVo> voList = voPage.getRecords();
        if (voList.isEmpty()) {
            return R.success(voPage);
        }
        //加载公司信息
        for (ExhibitorVo exhibitorVo : voList) {
            CompanyVo companyVo = companyService.findById(exhibitorVo.getCompanyId());
            if (companyVo != null) {
                exhibitorVo.setCompanyVo(companyVo);
            }
        }
        voPage.setRecords(voList);
        return R.success(voPage);
    }

    @Override
    public R<Page<ExhibitorVo>> queryPageDetails(PageParams<ExhibitorDTO> params) {
        Page<ExhibitorVo> exhibitorVoPage = myExhibitorMapper.queryPageDetails(params.buildPage(), params.getModel(), ContextUtil.getProjectId());
        //组装内容
        List<ExhibitorVo> result = new ArrayList<>();
        List<ExhibitorVo> exhibitorVoList = exhibitorVoPage.getRecords();
        if (exhibitorVoList != null && !exhibitorVoList.isEmpty()) {
            for (ExhibitorVo exhibitorVo : exhibitorVoList) {
                exhibitorVo = findCompanyOfAll(exhibitorVo.getId());
                result.add(exhibitorVo);
            }
            exhibitorVoPage.setRecords(result);
        }
        return R.success(exhibitorVoPage);
    }


    public UserAccount executeExhibitorUser(ExhibitorExcelResultDTO exhibitorExcelResultDTO, Long projectId) {
        UserAccountDto userAccountDto = new UserAccountDto();
        userAccountDto.setMobile(exhibitorExcelResultDTO.getContactMobile());
        userAccountDto.setEmail(exhibitorExcelResultDTO.getContactEmail());
        return executeExhibitorUser(userAccountDto, projectId);
    }

    public UserAccount executeExhibitorUser(UserAccountDto userAccountDto, Long projectId) {
        UserAccount userAccount = null;
        //查询员工是否存在，同时挂靠的公司是否正确
        String mobile = userAccountDto.getMobile();
        String email = userAccountDto.getEmail();
        if (StringUtils.isBlank(mobile) && StringUtils.isBlank(email)) {
            //添加虚拟账号
            userAccountDto.setProjectId(ContextUtil.getProjectId());
            R<UserAccountVo> accountVoR = userAccountServiceFeign.addAdminUser(userAccountDto);
            if (accountVoR.getCode() == SUCCESS_CODE) {
                UserAccountVo userAccountVo = accountVoR.getData();
                BeanUtils.copyProperties(userAccountVo, userAccount);
                return userAccount;
            }
        } else {
            R<UserAccount> userAccountR = userAccountServiceFeign.queryOfPhoneOrEmail(mobile, email);
            if (userAccountR.getCode() == SUCCESS_CODE) {
                userAccount = userAccountR.getData();
                if (userAccount == null) {
                    //新增用户
                    userAccount = new UserAccount();
                    R<UserAccountVo> userAccountVoR = userAccountServiceFeign.register(userAccountDto);
                    if (userAccountVoR.getCode() == SUCCESS_CODE) {
                        UserAccountVo userAccountVo = userAccountVoR.getData();
                        BeanUtils.copyProperties(userAccountVo, userAccount);
                    }
                }
            }
        }

        return userAccount;
    }

    public Company executeExhibitorCompany(ExhibitorExcelResultDTO exhibitorExcelResultDTO, Long projectId, Long userId) {
        CompanyDTO companyDTO = new CompanyDTO();
        BeanUtils.copyProperties(exhibitorExcelResultDTO, companyDTO);
        return executeExhibitorCompany(companyDTO, projectId, userId);
    }

    public Company executeExhibitorCompany(CompanyDTO companyDTO, Long projectId, Long userId) {
        Company company = new Company();
        if (companyDTO.getId() != null) {
            BeanUtils.copyProperties(companyDTO, company);
            companyService.updateById(company);
        } else {
            //查询公司是否存在
            company.setName(companyDTO.getName());
            List<Company> companyList = companyService.list(company, null);
            if (companyList == null || companyList.isEmpty()) {
                //新增公司
                CompanyVo companyVo = companyService.saveCompany(companyDTO, userId);
                BeanUtils.copyProperties(companyVo, company);
            } else {
                //修改公司
                company = companyList.get(0);
                BeanUtils.copyProperties(companyDTO, company, new String[]{"id"});
                companyService.updateById(company);
            }
        }

        //添加到事件监听队列
        BusinLoadUserRelevancePoint businLoadUserRelevancePoint = new BusinLoadUserRelevancePoint();
        businLoadUserRelevancePoint.setUserId(userId);
        businLoadUserRelevancePoint.setCompanyId(company.getId());
        businLoadUserRelevancePoint.setProjectId(ContextUtil.getProjectId());
        pointUtil.addBusinPointMsg(businLoadUserRelevancePoint);
        return company;
    }

    public Exhibitor executeExhibitor(ExhibitorExcelResultDTO exhibitorExcelResultDTO, Long exhibitionId, Long projectId, Long companyId, Long userId) {
        ExhibitorDTO exhibitorDTO = new ExhibitorDTO();
        exhibitorDTO.setCompanyId(companyId);
        exhibitorDTO.setExhibitionId(exhibitionId);
        BeanUtils.copyProperties(exhibitorExcelResultDTO, exhibitorDTO, new String[]{"id", "exhibitionId", "companyId", "projectId"});
        return executeExhibitor(exhibitorDTO, projectId,userId);
    }

    public Exhibitor executeExhibitor(ExhibitorDTO exhibitorDTO, Long projectId, Long userId) {
        //查询展商是否存在
        Exhibitor exhibitor = new Exhibitor();
        if (exhibitorDTO.getId() != null) {
            BeanUtils.copyProperties(exhibitorDTO, exhibitor);
            exhibitorService.updateById(exhibitor);
        } else {
            exhibitor.setCompanyId(exhibitorDTO.getCompanyId());
            exhibitor.setExhibitionId(exhibitorDTO.getExhibitionId());
            List<Exhibitor> exhibitorList = exhibitorService.list(exhibitor, null);
            if (exhibitorList == null || exhibitorList.isEmpty()) {
                //新增展商
                exhibitor.setProjectId(projectId);
                BeanUtils.copyProperties(exhibitorDTO, exhibitor, new String[]{"id", "exhibitionId", "companyId", "projectId"});
                exhibitorService.save(exhibitor);
            } else {
                //修改公司
                exhibitor = exhibitorList.get(0);
                BeanUtils.copyProperties(exhibitorDTO, exhibitor, new String[]{"id", "exhibitionId", "companyId", "projectId"});
                exhibitorService.updateById(exhibitor);
            }
        }
        //添加到事件监听队列
        if(userId!=null){
            BusinLoadUserRelevancePoint businLoadUserRelevancePoint = new BusinLoadUserRelevancePoint();
            businLoadUserRelevancePoint.setUserId(userId);
            businLoadUserRelevancePoint.setCompanyId(exhibitor.getId());
            businLoadUserRelevancePoint.setProjectId(ContextUtil.getProjectId());
            pointUtil.addBusinPointMsg(businLoadUserRelevancePoint);
        }
        return exhibitor;
    }

    @Override
    public String verifyExhibitor(Long exhibitionId, Long projectId, List<ExhibitorExcelDTO> exhibitorExcelDTOList) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < exhibitorExcelDTOList.size(); i++) {
            ExhibitorExcelDTO exhibitorExcelDTO = exhibitorExcelDTOList.get(i);
            //检测用户是否挂靠在该公司上
            //查询员工是否存在，同时挂靠的公司是否正确
            R<UserAccount> userAccountR = userAccountServiceFeign.queryOfPhoneOrEmail(exhibitorExcelDTO.getContactMobile(), exhibitorExcelDTO.getContactEmail());
            if (userAccountR.getCode() == SUCCESS_CODE) {
                UserAccount userAccount = userAccountR.getData();
                if (userAccount != null) {
                    Employee employee = new Employee();
                    employee.setUserAccountId(userAccount.getId());
                    List<Employee> employeeList = employeeService.list(employee, null);
                    if (employeeList != null && !employeeList.isEmpty()) {
                        Company company = companyService.getById(employeeList.get(0).getCompanyId());
                        if (company != null && !company.getName().equals(exhibitorExcelDTO.getName())) {
                            stringBuffer.append(String.format("第%s行：联系人和展商不匹配", i + 1, exhibitorExcelDTO.getName()));
                        }
                    }
                }
            }
        }

        return stringBuffer.toString();
    }

    @Override
    public List<ExhibitorExcelResultDTO> convertExhibitor(Long exhibitionId, Long projectId, List<ExhibitorExcelDTO> exhibitorExcelDTOList) {
        List<ExhibitorExcelResultDTO> exhibitorExcelResultDTOList = new ArrayList<>();
        for (ExhibitorExcelDTO exhibitorExcelDTO : exhibitorExcelDTOList) {
            ExhibitorExcelResultDTO exhibitorExcelResultDTO = new ExhibitorExcelResultDTO();
            BeanUtils.copyProperties(exhibitorExcelDTO, exhibitorExcelResultDTO);
            // TODO: 2021/12/8  组装国家省市信息
            Area area = new Area();
            //国家
            area.setName(exhibitorExcelResultDTO.getCountryName());
            area.setLevel("4");
            R<List<AreaVO>> r = projectCoreServiceFeign.queryListArea(area);
            if (r.getCode() == SUCCESS_CODE && r.getData() != null && !r.getData().isEmpty()) {
                List<AreaVO> areaVOList = r.getData();
                exhibitorExcelResultDTO.setCountryId(areaVOList.get(0).getId());
            }

            //省份
            area = new Area();
            area.setName(exhibitorExcelResultDTO.getProvinceName());
            area.setLevel("3");
            r = projectCoreServiceFeign.queryListArea(area);
            if (r.getCode() == SUCCESS_CODE && r.getData() != null && !r.getData().isEmpty()) {
                List<AreaVO> areaVOList = r.getData();
                exhibitorExcelResultDTO.setProvinceId(areaVOList.get(0).getId());
            }
            //城市
            area = new Area();
            area.setName(exhibitorExcelResultDTO.getCityName());
            area.setLevel("2");
            r = projectCoreServiceFeign.queryListArea(area);
            if (r.getCode() == SUCCESS_CODE && r.getData() != null && !r.getData().isEmpty()) {
                List<AreaVO> areaVOList = r.getData();
                exhibitorExcelResultDTO.setCityId(areaVOList.get(0).getId());
            }

            exhibitorExcelResultDTOList.add(exhibitorExcelResultDTO);
        }
        return exhibitorExcelResultDTOList;
    }

    @Override
    public void batchSave(Long exhibitionId, Long projectId, List<ExhibitorExcelResultDTO> exhibitorExcelResultDTOList) {
        /**
         * 组装展商：
         * 1用户不存在，添加用户
         * 2公司不存在，添加公司
         * 3展商不存在，添加展商
         * 3展商存在，则修改展商和公司
         */
        for (ExhibitorExcelResultDTO exhibitorExcelResultDTO : exhibitorExcelResultDTOList) {
            //导入用户信息
            UserAccount userAccount = executeExhibitorUser(exhibitorExcelResultDTO, projectId);
            //导入公司信息
            Company company = executeExhibitorCompany(exhibitorExcelResultDTO, projectId, userAccount.getId());
            //导入展商信息
            executeExhibitor(exhibitorExcelResultDTO, exhibitionId, projectId, company.getId(),userAccount.getId());
        }
    }

    @Override
    public R<ExhibitorVo> addExhibitor(ExhibitorCompanyDTO exhibitorCompanyDTO, Long projectId) {
        //添加用户信息
        UserAccount userAccount = executeExhibitorUser(exhibitorCompanyDTO.getUserAccountDto(), projectId);
        //添加公司信息
        Company company = executeExhibitorCompany(exhibitorCompanyDTO.getCompanyDTO(), projectId, userAccount.getId());
        //添加展商信息
        ExhibitorDTO exhibitorDTO = exhibitorCompanyDTO.getExhibitorDTO();
        exhibitorDTO.setCompanyId(company.getId());
        Exhibitor exhibitor = executeExhibitor(exhibitorDTO, projectId,userAccount.getId());
        ExhibitorVo exhibitorVo = new ExhibitorVo();
        BeanUtils.copyProperties(exhibitor, exhibitorVo);
        exhibitorVo.setId(exhibitor.getId());
        return R.success(exhibitorVo);
    }

    @Override
    public R<ExhibitorVo> updExhibitor(ExhibitorCompanyDTO exhibitorCompanyDTO, Long projectId) {
        //修改公司和展商
        Company company = executeExhibitorCompany(exhibitorCompanyDTO.getCompanyDTO(), projectId, null);
        //添加展商信息
        ExhibitorDTO exhibitorDTO = exhibitorCompanyDTO.getExhibitorDTO();
        exhibitorDTO.setCompanyId(company.getId());
        Exhibitor exhibitor = executeExhibitor(exhibitorDTO, projectId,null);
        ExhibitorVo exhibitorVo = new ExhibitorVo();
        BeanUtils.copyProperties(exhibitor, exhibitorVo);
        exhibitorVo.setId(exhibitor.getId());
        return R.success(exhibitorVo);
    }


    public ExhibitorVo exhibitorDetail(Long id) {
        ExhibitorVo result = new ExhibitorVo();
        Exhibitor exhibitor = getById(id);
        BeanUtils.copyProperties(exhibitor, result);
        result.setId(exhibitor.getId());
        CompanyVo companyVo = companyService.findAllUserById(exhibitor.getCompanyId());
        result.setCompanyVo(companyVo);
        //公司下的员工
        List<EmployeeVo> employeeVoList = companyVo.getEmployeeVoList();
        if (employeeVoList != null && !employeeVoList.isEmpty()) {
            for (EmployeeVo employeeVo : employeeVoList) {
                if (employeeVo.getIsAdmin() == BusinessConstant.YES) {
                    UserAccountDto userAccountDto = new UserAccountDto();
                    userAccountDto.setUserIds(Arrays.asList(employeeVo.getUserAccountId()));
                    R<List<UserAccountVo>> r = userAccountServiceFeign.querySimpleByIds(userAccountDto);
                    if (r.getCode() == SUCCESS_CODE) {
                        List<UserAccountVo> userAccountVoList = r.getData();
                        if (userAccountVoList != null && !userAccountVoList.isEmpty()) {
                            result.setUserAccountVo(userAccountVoList.get(0));
                        }
                    }
                    break;
                }
            }
        }
        return result;
    }

    @Override
    public ExhibitorVo exhibitorDetailOfEdit(Long id) {
        ExhibitorVo result = new ExhibitorVo();
        Exhibitor exhibitor = getById(id);
        BeanUtils.copyProperties(exhibitor, result);
        result.setId(exhibitor.getId());
        CompanyVo companyVo = companyService.findById(exhibitor.getCompanyId());
        result.setCompanyVo(companyVo);
        return result;
    }

    @Override
    public List<ExhibitorVo> queryByIds(List<Long> ids) {
        List<ExhibitorVo> exhibitorVoList = new ArrayList<>();
        if (ids != null && !ids.isEmpty()) {
            ids.forEach(s->{
                exhibitorVoList.add(findCompanyOfAll(s));
            });
        }
        return exhibitorVoList;
    }
}
